<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/1/25
 * Time: 9:33
 */


$str = 'hello world';
$result = md5($str);
echo $result . PHP_EOL;
$result = md5($str, true);
echo $result . PHP_EOL;

////////////////////////////////////////////

$result = md5_file(__FILE__);
echo basename(__FILE__) . '-->' . $result . PHP_EOL;
echo basename(__FILE__) . '-->' . md5_file(__FILE__) . PHP_EOL;
//var_dump(pathinfo(__FILE__));
echo basename(__FILE__) . '-->' . md5_file(__FILE__, true) . PHP_EOL;


function md5bin($target)
{
    $md5 = md5($target);
    $ret = '';

    for ($i = 0; $i < 32; $i += 2) {
        $ret .= chr(hexdec($md5{$i + 1}) + hexdec($md5{$i}) * 16);
    }
    return $ret;
}

echo md5bin($str) . PHP_EOL;
echo md5($str, true) . PHP_EOL;

function checksum($what, $depth = 1)
{
    $depth--;
    if (!$depth)
        return md5($what);
    else
        return md5(checksum($what, $depth));
}

for ($i = 1; $i <= 10; $i++) {
    echo "$i. " . checksum($str, $i) . PHP_EOL;
}
